package com.whisper.application.service.service.impl;

import java.util.List;

import com.whisper.common.constant.UserConstants;
import com.whisper.common.utils.DateUtils;
import com.whisper.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.whisper.application.service.mapper.VrUserMapper;
import com.whisper.application.service.domain.VrUser;
import com.whisper.application.service.service.IVrUserService;

/**
 * 前台用户信息Service业务层处理
 * 
 * @author whisper
 * @date 2024-01-07
 */
@Service
public class VrUserServiceImpl implements IVrUserService 
{
    @Autowired
    private VrUserMapper vrUserMapper;

    /**
     * 查询前台用户信息
     * 
     * @param id 前台用户信息主键
     * @return 前台用户信息
     */
    @Override
    public VrUser selectVrUserById(Long id)
    {
        return vrUserMapper.selectVrUserById(id);
    }

    /**
     * 查询前台用户信息列表
     * 
     * @param vrUser 前台用户信息
     * @return 前台用户信息
     */
    @Override
    public List<VrUser> selectVrUserList(VrUser vrUser)
    {
        return vrUserMapper.selectVrUserList(vrUser);
    }

    /**
     * 新增前台用户信息
     * 
     * @param vrUser 前台用户信息
     * @return 结果
     */
    @Override
    public int insertVrUser(VrUser vrUser)
    {
        vrUser.setCreateTime(DateUtils.getNowDate());
        return vrUserMapper.insertVrUser(vrUser);
    }

    /**
     * 修改前台用户信息
     * 
     * @param vrUser 前台用户信息
     * @return 结果
     */
    @Override
    public int updateVrUser(VrUser vrUser)
    {
        vrUser.setUpdateTime(DateUtils.getNowDate());
        return vrUserMapper.updateVrUser(vrUser);
    }

    /**
     * 批量删除前台用户信息
     * 
     * @param ids 需要删除的前台用户信息主键
     * @return 结果
     */
    @Override
    public int deleteVrUserByIds(Long[] ids)
    {
        return vrUserMapper.deleteVrUserByIds(ids);
    }

    /**
     * 删除前台用户信息信息
     * 
     * @param id 前台用户信息主键
     * @return 结果
     */
    @Override
    public int deleteVrUserById(Long id)
    {
        return vrUserMapper.deleteVrUserById(id);
    }

    @Override
    public VrUser selectUserByUserName(String username) {
        return vrUserMapper.selectUserByUserName(username);
    }

    @Override
    public int selectUserCount() {
        return vrUserMapper.selectUserCount();
    }

    @Override
    public boolean updateUserAvatar(String username, String avatar) {
        return vrUserMapper.updateUserAvatar(username, avatar) > 0;
    }

    @Override
    public boolean checkUserNameUnique(VrUser user) {
        Long userId = StringUtils.isNull(user.getId()) ? -1L : user.getId();
        VrUser info = vrUserMapper.checkUserNameUnique(user.getUsername());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != userId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public boolean registerUser(VrUser user) {
        return vrUserMapper.insertVrUser(user) > 0;
    }

    @Override
    public int resetPwd(VrUser user) {
        return vrUserMapper.updateVrUser(user);
    }
}
